/*
<license>
Copyright (c) 2008, Chris Venter <chris.venter@gmail.com>
All rights reserved.

This file is part of quicktag <http://code.google.com/p/quicktag/>

quicktag is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

quicktag is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this code.
If not, see <http://www.gnu.org/licenses/>.
</license>
*/
#ifndef QUICKTAG_H
#define QUICKTAG_H

/** \file etag.h
This file contains definitions for use by the etag library of functions.

The etag library provides an easy to use interface to extract (read-only at
the moment) meta-data from a variety of audio formats.

These are
	- mp3
	- wma
	- mp4/m4a
	- ogg

Most of the code in this file, as well as others, come directly from the 
"easytag" project: http://easytag.sourceforge.net/
Easytag itself borrows and uses code from other projects, for example glib.
It is released under the GPL License, and therefore I release this code under
the GPL as well.

The code is not production quality, but useful enough so that I can release it
as is. Work will continue to improve the quality!

Chris Venter 2008
<chris.venter@gmail.com>

\todo Other formats may be included in future.
\todo Write support is also planned.
\todo 
*/

#include <glib.h>
#include <string>

#define NUMBER_TRACK_FORMATED 0
#define NUMBER_TRACK_FORMATED_SPIN_BUTTON 0
#define USE_NON_STANDARD_ID3_READING_CHARACTER_SET 0
#define FILE_WRITING_ID3V2_USE_UNICODE_CHARACTER_SET 0

#define EASYTAG_STRING_ENCODEDBY "Encoded by"
#define MULTIFIELD_SEPARATOR " - "

#define _(X) X

const gchar *get_locale (void);
/* stolen from gnome-desktop-item.c */
const char* get_encoding_from_locale(const char* locale);
void Charset_Insert_Locales_Init(void);
gchar* Try_To_Validate_Utf8_String (const gchar *string);

enum READ_VAL
{
	READVAL_OK = 0,		// indicates a succesful read
	READVAL_UNKNOWN,	// indicates that the file type could not be identified
	READVAL_FILE,		// indicates that a file-open error occured
	READVAL_ACCESS,		// indicates that a file-access error occurred
	READVAL_FAIL		// indicates that a general error occurred
};

/*
 * Types of files
 */
typedef enum
{                    //                                             (.ext) is not so popular 
    MP2_FILE = 0,    // Mpeg audio Layer 2        : .mp2            (.mpg) (.mpga)
    MP3_FILE,        // Mpeg audio Layer 3        : .mp3            (.mpg) (.mpga)
    MP4_FILE,        // Mpeg audio Layer 4 / AAC  : .mp4            (.m4a) (.m4p)
    OGG_FILE,        // Ogg Vorbis audio          : .ogg            (.ogm)
    FLAC_FILE,       // FLAC (lossless)           : .flac .fla
    MPC_FILE,        // MusePack                  : .mpc .mp+ .mpp
    MAC_FILE,        // Monkey's Audio (lossless) : .ape            (.mac)
    SPEEX_FILE,      // Speech audio files        : .spx
    OFR_FILE,        // OptimFROG (lossless)      : .ofr .ofs
    WAVPACK_FILE,    // Wavpack (lossless)        : .wv
    UNKNOWN_FILE
} ET_File_Type;


/*
 * Types of tags
 */
typedef enum
{
    ID3_TAG = 0,
    OGG_TAG,
    APE_TAG,
    FLAC_TAG,
    MP4_TAG,
    WAVPACK_TAG,
    UNKNOWN_TAG
} ET_Tag_Type;

/*
typedef struct _Picture Picture;
struct _Picture
{
    gint     type;
    gchar   *description;
    gint     width;         // Original width of the picture 
    gint     height;        // Original height of the picture 
    gulong   size;          // Picture size in bytes (like stat) 
    guchar  *data;
    Picture *next;
    
    _Picture()
    : type(0)
    , description(0)
    , width(0), height(0), size(0)
    , data(0)
    , next(0)
    {}
};
*/

//Picture* Picture_Allocate();

/*
 * Description of each item of the TagList list
 */
 /*
typedef struct _File_Tag File_Tag;
struct _File_Tag
{
    //guint key;             // Incremented value 
    //gboolean saved;        // Set to TRUE if this tag had been saved 

    gchar *title;          // Title of track 
    gchar *artist;         // Artist name 
    gchar *album;          // Album name 
    gchar *disc_number;    // Disc number 
    gchar *year;           // Year of track 
    gchar *track;          // Position of track in the album 
    gchar *track_total;    // The number of tracks for the album (ex: 12/20) 
    gchar *genre;          // Genre of song 
    gchar *comment;        // Comment 
    gchar *composer;       // Composer 
    gchar *orig_artist;    // Original artist / Performer 
    gchar *copyright;      // Copyright 
    gchar *url;            // URL 
    gchar *encoded_by;     // Encoded by 
    Picture *picture;      // Picture 
    GList *other;          // List of unsupported fields (used for ogg only) 
    
    _File_Tag()
    : title(0)
    , artist(0)
    , album(0)
    , disc_number(0)
    , year(0)
    , track(0)
    , track_total(0)
    , genre(0)
    , comment(0)
    , composer(0)
    , orig_artist(0)
    , copyright(0)
    , url(0)
    , encoded_by(0)
    , picture(0)
    , other(0)
    {}
};
*/
namespace quicktag
{
	struct tags
	{
		tags()
		: ok(true)
		{}
		
		std::string title;// Title of track 
		std::string artist;// Artist name 
		std::string album;// Album name 
		std::string discnumber;// Disc number 
		std::string year;// Year of track 
		std::string tracknr;// Position of track in the album 
		std::string ntracks;// The number of tracks for the album (ex: 12/20) 
		std::string genre;// Genre of song 
		std::string comment;// Comment

		std::string error;
		bool ok;
		//std::string composer;       // Composer 
		//std::string orig_artist;    // Original artist / Performer 
		//std::string copyright;      // Copyright 
		//std::string url;            // URL 
		//std::string encoded_by;     // Encoded by 
		//Picture *picture;      // Picture 
		//GList *other;          // List of unsupported fields (used for ogg only)

		void seterror(const std::string& message)
		{
			error = message;
			ok = false;
		}
		
		void init()
		{
			title 		= "<Unknown Track>";
			artist 		= "<Unknown Artist>";
			album 		= "<Unknown Album>";
			discnumber 	= "0";
			year 		= "0";
			tracknr 	= "0";
			ntracks 	= "0";
			genre 		= "<Unknown>";
			comment 	= "0";
			
			error = "";
			ok = true;
		}
		
		void clear()
		{
			title 		= "";
			artist 		= "";
			album 		= "";
			discnumber 	= "";
			year 		= "";
			tracknr 	= "";
			ntracks 	= "";
			genre 		= "";
			comment 	= "";
			
			error = "";
			ok = true;
		}
		
	};

	int read_file(const std::string& filename, quicktag::tags& tags);

}


/*
 * Structure containing informations of the header of file
 * Nota: This struct was copied from an "MP3 structure", and will change later.
 */
 /*
typedef struct _ET_File_Info ET_File_Info;
struct _ET_File_Info
{
    gint version;               // Version of bitstream (mpeg version for mp3, encoder version for ogg) 
    gint mpeg25;                // Version is MPEG 2.5? 
    gint layer;                 // "MP3 data" 
    gint bitrate;               // Bitrate (kb/s) 
    gboolean variable_bitrate;  // Is a VBR file? 
    gint samplerate;            // Samplerate (Hz) 
    gint mode;                  // Stereo, ... or channels for ogg 
    gint size;                  // The size of file (in bytes) 
    gint duration;              // The duration of file (in seconds) 
    gchar *mpc_profile;         // MPC data 
    gchar *mpc_version;         // MPC data : encoder version  (also for Speex) 
};
*/

/*
 * Structure for descripting supported files
 */
 /*
typedef struct _ET_File_Description ET_File_Description;
struct _ET_File_Description
{
    ET_File_Type FileType;    // Type of file (ex: MP3) 
    const gchar *Extension;   // Extension (ex: ".mp3") 
    ET_Tag_Type  TagType;     // Type of tag (ex: ID3) 
};
*/

/*
 * Description of supported files
 */
 /*
static const ET_File_Description ETFileDescription[] = 
{
#ifdef ENABLE_MP3
    {MP3_FILE,     ".mp3",  ID3_TAG},
    {MP2_FILE,     ".mp2",  ID3_TAG},
#endif
#ifdef ENABLE_OGG
    {OGG_FILE,     ".ogg",  OGG_TAG},
    {OGG_FILE,     ".oga",  OGG_TAG},
#endif
#ifdef ENABLE_SPEEX
    {SPEEX_FILE,   ".spx",  OGG_TAG},  // Implemented by Pierre Dumuid
#endif
#ifdef ENABLE_FLAC
    {FLAC_FILE,    ".flac", FLAC_TAG},
    {FLAC_FILE,    ".fla",  FLAC_TAG},
#endif
    {MPC_FILE,     ".mpc",  APE_TAG},  // Implemented by Artur Polaczynski
    {MPC_FILE,     ".mp+",  APE_TAG},  // Implemented by Artur Polaczynski
    {MPC_FILE,     ".mpp",  APE_TAG},  // Implemented by Artur Polaczynski
    {MAC_FILE,     ".ape",  APE_TAG},  // Implemented by Artur Polaczynski
    {MAC_FILE,     ".mac",  APE_TAG},  // Implemented by Artur Polaczynski
    {OFR_FILE,     ".ofr",  APE_TAG},
    {OFR_FILE,     ".ofs",  APE_TAG},
#ifdef ENABLE_MP4
    {MP4_FILE,     ".mp4",  MP4_TAG},  // Implemented by Michael Ihde
    {MP4_FILE,     ".m4a",  MP4_TAG},  // Implemented by Michael Ihde
    {MP4_FILE,     ".m4p",  MP4_TAG},  // Implemented by Michael Ihde
#endif
#ifdef ENABLE_WAVPACK
    {WAVPACK_FILE, ".wv",   WAVPACK_TAG}, // Implemented by Maarten Maathuis
#endif
    {UNKNOWN_FILE, "",      UNKNOWN_TAG}    // This item must be placed to the end!
};
*/

/* Calculate the last index of the previous tab */
//#define ET_FILE_DESCRIPTION_SIZE ( sizeof(ETFileDescription)/sizeof(ETFileDescription[0]) - 1 )


/*
 * Description of each item of the ETFileList list
 */
 /*
typedef struct _ET_File ET_File;
struct _ET_File
{
    guint IndexKey;           // Value used to display the position in the list (and in the BrowserList) - Must be renumered after resorting the list - This value varies when resorting list 

    guint ETFileKey;          // Primary key to identify each item of the list (no longer used?) 

    time_t FileModificationTime;            // Save modification time of the file 

    ET_File_Description *ETFileDescription;
    gchar               *ETFileExtension;   // Real extension of the file (keeping the case) (should be placed in ETFileDescription?) 
    ET_File_Info        *ETFileInfo;        // Header infos: bitrate, duration, ... 

    GList *FileNameCur;       // Points to item of FileNameList that represents the current value of filename state (i.e. file on hard disk) 
    GList *FileNameNew;       // Points to item of FileNameList that represents the new value of filename state 
    GList *FileNameList;      // Contains the history of changes about the file name 
    GList *FileNameListBak;   // Contains items of FileNameList removed by 'undo' procedure but have data currently saved (for example, when you save your last changes, make some 'undo', then make new changes) 
    
    GList *FileTag;           // Points to the current item used of FileTagList 
    GList *FileTagList;       // Contains the history of changes about file tag data 
    GList *FileTagListBak;    // Contains items of FileTagList removed by 'undo' procedure but have data currently saved 
    
};
*/

#endif


